<?php

namespace App\Helpers;

use EasyWeChat\OfficialAccount\Application;


class WeChatHelper
{
    public $app;
    public $utils;

    public function __construct($config)
    {
        $config = array_merge([
            'app_id'  => 'your-app-id',         // AppID
            'secret'  => 'your-app-secret',     // AppSecret
            'http' => [
                'timeout' => 5.0,
                'verify' => false,
                'retry' => true,
            ],
        ],$config);
        $this->app = new Application($config);
    }

    /**
     * @param  string  $url
     * @param  array<string>  $jsApiList
     * @param  array<string>  $openTagList
     * @return array<string, mixed>
     */
    public function buildJsSdkConfig(
        string $url,
        array $jsApiList = [],
        array $openTagList = []
    )
    {
        $utils = $this->app->getUtils();
        return $utils->buildJsSdkConfig(
            url: $url,
            jsApiList: $jsApiList,
            openTagList: $openTagList,
            debug: config('app.debug')
        );
    }

}
